import request from '@/utils/request';

/**
 * 分页查询入库单
 */
export async function pageEntryBill(params) {
  const res = await request.get('/store/entryBill/page', { params });
  if (res.data.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询入库单列表
 */
export async function listEntryBill(params) {
  const res = await request.get('/store/entryBill', { params });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询入库单
 */
export async function getEntryBill(id) {
  const res = await request.get('/store/entryBill/' + id);
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加入库单
 */
export async function addEntryBill(data) {
  const res = await request.post('/store/entryBill', data);
  if (res.data.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改入库单
 */
export async function updateEntryBill(data) {
  const res = await request.put('/store/entryBill', data);
  if (res.data.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 修改付款,开票状态
 */
export async function updateTableState(data) {
  const res = await request.put('/store/entryBill/updateTableState', data);
  if (res.data.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除入库单
 */
export async function removeEntryBill(id) {
  const res = await request.delete('/store/entryBill/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除入库单
 */
export async function removeEntryAndSon(id) {
  const res = await request.delete('/store/entryBill/removeEntryAndSon/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
